package com.market.controller.admin;

import com.market.bean.MarketGoods;
import com.market.bean.bo.admin.AdminCreateGoodsBeanBo;
import com.market.bean.common.BasePageInfo;
import com.market.bean.common.BaseRespVo;
import com.market.bean.common.CommonData;
import com.market.bean.vo.admin.AdminCatAndBrandVo;
import com.market.bean.vo.admin.AdminDetailGoodsBeanVo;
import com.market.service.admin.AdminGoodsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 商品管理
 *
 * @author wh194@foxmail.com
 * @since 2022/12/29 22:28
 */
@RestController
@RequestMapping("admin/goods")
public class AdminGoodsController {
    @Autowired
    AdminGoodsService goodsService;


    @GetMapping("list")
    public BaseRespVo list(BasePageInfo info, String goodsSn, String name, Integer goodsId) {
        CommonData<MarketGoods> data = goodsService.list(info, goodsSn, name, goodsId);
        return BaseRespVo.ok(data);
    }

    @GetMapping("catAndBrand")
    public BaseRespVo catAndBrand() {
        AdminCatAndBrandVo data = goodsService.catAndBrand();
        return BaseRespVo.ok(data);
    }

    @PostMapping("create")
    public BaseRespVo create(@RequestBody AdminCreateGoodsBeanBo createGoodsBeanBo) {
        goodsService.create(createGoodsBeanBo);
        return BaseRespVo.ok();
    }

    @PostMapping("update")
    public BaseRespVo update(@RequestBody AdminCreateGoodsBeanBo createGoodsBeanBo) {
        goodsService.update(createGoodsBeanBo);
        return BaseRespVo.ok();
    }

    @PostMapping("delete")
    public BaseRespVo delete(@RequestBody MarketGoods marketGoods) {
        goodsService.delete(marketGoods);
        return BaseRespVo.ok();
    }

    @GetMapping("detail")
    public BaseRespVo detail(Integer id) {
        AdminDetailGoodsBeanVo data = goodsService.detail(id);
        return BaseRespVo.ok(data);
    }


}
